package com.xquant.trade.trade.service.impl.other;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.xquant.common.core.exception.ServiceException;
import com.xquant.common.core.web.domain.AjaxResult;
import com.xquant.common.security.utils.DictUtils;
import com.xquant.system.api.RemoteDailyPriceService;
import com.xquant.system.api.RemoteDurationService;
import com.xquant.trade.account.entity.Account;
import com.xquant.trade.account.mapper.AccountMapper;
import com.xquant.trade.common.utils.StringUtils;
import com.xquant.trade.risk.entity.CombinedMonitorDetail;
import com.xquant.trade.systerm.mapper.InstrumentMapper;
import com.xquant.trade.trade.entity.BalanceChange;
import com.xquant.trade.trade.entity.Trade;
import com.xquant.trade.trade.entity.TradeStatus;
import com.xquant.trade.trade.mapper.TradePkgMapper;
import com.xquant.trade.trade.service.TradeService;
import com.xquant.trade.trade.service.impl.TradeServiceAbstract;
import com.xquant.trade.utils.CommResponse;
import com.xquant.trade.utils.DateUtils;
import com.xquant.trade.utils.ExcelImportUtil;
import com.xquant.trade.utils.SysUtils;
import io.seata.core.context.RootContext;
import io.seata.core.exception.TransactionException;
import io.seata.spring.annotation.GlobalTransactional;
import io.seata.tm.api.GlobalTransactionContext;
import org.apache.commons.collections.ListUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicStampedReference;

/**
 * newCloud 场内交易
 * 场内交易
 */
@Component
public class TradeServiceImpl4SimpleTrade extends TradeServiceAbstract {
    private static Logger logger = LoggerFactory.getLogger(TradeServiceImpl4SimpleTrade.class);
    @Autowired
    public TradePkgMapper tradePkgMapper;
    @Autowired
    private AccountMapper accountMapper;
    @Autowired
    private InstrumentMapper instrumentMapper;

    @Autowired
    private RemoteDurationService remoteDurationService;

    AtomicStampedReference<Long> atomicStampedRef = new AtomicStampedReference<>(1000L, 0);
    // 用于存储当前的时间戳
    int[] stampHolder = new int[1];
    // 获取当前值和版本号
    Long currentValue = atomicStampedRef.get(stampHolder);

    /**
     * newCloud
     * 场内对冲交易
     * 交易类型
     */
    @Override
    public String[] getTradeTypes() {
        return new String[]{
                "LongOpen",
                "LongClose",
                "ShortOpen",
                "ShortClose"
        };
    }

    /**
     * newCloud
     * 场内对冲交易
     * 保存前 数据处理
     */
    @Override
    public void prepareTrade(Trade trade) {
        super.prepareTrade(trade);
        switch (trade.getTradeType()) {
            case "LongOpen":
                trade.setOcFlag("O");
                trade.setDimLs("L");
                trade.setPayDirection("1");
                return;
            case "LongClose":
                trade.setOcFlag("C");
                trade.setDimLs("L");
                trade.setPayDirection("1");
                return;
            case "ShortOpen":
                trade.setOcFlag("O");
                trade.setDimLs("S");
                trade.setPayDirection("-1");
                return;
            case "ShortClose":
                trade.setOcFlag("C");
                trade.setDimLs("S");
                trade.setPayDirection("-1");
                return;
        }
    }
    /**
     * newCloud
     * 场内对冲交易
     * 新增交易
     */
    /**
     * newCloud
     * 场外期权 新增交易
     */
    @Override
    @GlobalTransactional(name = "my_test_tx_group", rollbackFor = Exception.class)
    public CommResponse insertTrade(Trade trade) {

        trade.setTradeId(DateUtils.getCurr_YYYYMMDDHHMMSSSSS() + RandomUtil.randomNumbers(3));
        trade.setVersion(1000);
        super.insertTrade(trade);
        //confirmTrade(trade);
        //报送 保存到pricing 模拟
        Map<String, Object> params = new HashMap<>();
        params.put("tradeId", trade.getTradeId());
        params.put("durationId", trade.getTradeId());
        params.put("eventStatus", 1);
        params.put("npv", 9999);
        AjaxResult ajaxResult = remoteDurationService.insertDuration(params);
        //如果开启分布式事务,设置错误状态码,让事务回滚
        if (StringUtils.isNotBlank(RootContext.getXID())) {
            if(Integer.parseInt(ajaxResult.get("code").toString()) < 0){
                logger.error("全局捕异常 捕获到Seata " + " 事务id-------------API--------->" + RootContext.getXID());
                logger.error("全局捕异常 捕捉到Seata 事务" + RootContext.getXID() + " 抛出异常 设置response 状态码为 500 ");
                logger.error("全局捕获到 Seata异常 全局回滚");
                try {
                    GlobalTransactionContext.reload(RootContext.getXID()).rollback();
                    logger.error(" 数据提交失败");
                } catch (TransactionException e) {
                    logger.error(" 捕获seata异常·不处理");
                }
            }

        }
        return CommResponse.success();
    }

    /**
     * 成交
     */
    @Override
    public CommResponse confirmTrade(Trade trade) {
        CommResponse commResponse = CommResponse.success();
        prepareTrade(trade);
        //如果状态不为2，需要更新交易状态

        if (!TradeStatus.DEAL.equals(trade.getTradeStatus())) {
            trade.setTradeStatus(TradeStatus.DEAL);
            tradeMapper.updateTradeStatus(trade);
            // 交易明细
            if (trade.getDetails() != null && trade.getDetails().size() > 0) {
                for (int i = 0; i < trade.getDetails().size(); i++) {
                    trade.getDetails().get(i).setTradeStatus(TradeStatus.DEAL);
                    tradeMapper.updateTradeStatus(trade.getDetails().get(i));
                }
            }
        }
        // 主交易记账
        List<BalanceChange> lst = getBalanceChange(trade);
        for (int i = 0; i < lst.size(); i++) {
            BalanceChange change = lst.get(i);
            if (change.getChangeDate() == null) {
                change.setChangeDate(DateUtils.getCurr_YYYY_MM_DD());
            }
            tradeMapper.insertBalanceChange(change);
            if (change.getChangeDate() != null && change.getChangeDate().equals(settleService.getBlcDate())) {
                commResponse = this.tradeProcessBalanceChange(change);
                if (!commResponse.isSuccess()) {
                    return commResponse;
                }
            }
        }
        // 交易明细记账
        if (trade.getDetails() != null && trade.getDetails().size() > 0) {
            for (int i = 0; i < trade.getDetails().size(); i++) {
                TradeService service = factory.getTradeService(trade.getDetails().get(i).getTradeType());
                trade.getDetails().get(i).setTradeStatus(TradeStatus.DEAL);
                commResponse = service.confirmTrade(trade.getDetails().get(i));
                if (!commResponse.isSuccess()) {
                    return commResponse;
                }
            }
        }
        return CommResponse.success();
    }

    /**
     * 更新交易
     */
    @Override
    public CommResponse updateTrade(Trade trade) {
        prepareTrade(trade);
        //@view 乐观锁  CAS乐观锁实现 带时间戳
        Long newValue = currentValue + 1;
        int newStamp = stampHolder[0] + 1;
        // 尝试更新值和版本号
        boolean updated = atomicStampedRef.compareAndSet(currentValue, newValue, stampHolder[0], newStamp);
        if (updated) {
            // 更新主交易
            tradeMapper.updateTrade(trade);
        } else {
            throw new ServiceException("交易版本已修改，请刷新页面后，再进行修改");
        }
        // 再次获取更新后的值和版本号
        currentValue = atomicStampedRef.get(stampHolder);
        System.out.println("Updated value: " + currentValue + ", Stamp: " + stampHolder[0]);


        // 如果是已经成交的交易，重新记账
        if (TradeStatus.DEAL.equals(trade.getTradeStatus())) {
            // 更新主交易
            List<BalanceChange> oldLst = tradeMapper.queryBalanceChange(trade);
            // 生成新的变动
            tradeMapper.deleteBalanceChange(trade);
            List<BalanceChange> newLst = getBalanceChange(trade);
            for (int i = 0; i < newLst.size(); i++) {
                BalanceChange change = newLst.get(i);
                if (change.getChangeDate() == null) {
                    change.setChangeDate(DateUtils.getCurr_YYYY_MM_DD());
                }
                tradeMapper.insertBalanceChange(change);
            }
            // 合并变动，并重跑
            List<BalanceChange> lst = mergeBalanceChange(newLst, oldLst);
            for (int i = 0; i < lst.size(); i++) {
                BalanceChange change = lst.get(i);
                this.tradeRollbackBalance(change);
                this.tradeProcessTrade(change);
            }
        }
        return CommResponse.success();
    }

    /**
     * 交易撤单前校验
     */
    @Override
    public CommResponse checkRevertTrade(Trade trade) {

        return new CommResponse(true);
    }

    /**
     * 交易撤单 作废 9
     */
    @Override
    public void revertTrade(Trade trade) {
        trade.setTradeStatus(TradeStatus.REVERT);
        prepareTrade(trade);
        // 删除主交易
        tradeMapper.updateTradeStatus(trade);
        // 如果不是已经成交的交易，不处理记账
        // 查询原来的变动
        trade.setAccId(null);
        List<BalanceChange> oldLst = tradeMapper.queryBalanceChange(trade);
        tradeMapper.deleteBalanceChange(trade);
        for (int i = 0; i < oldLst.size(); i++) {
            BalanceChange change = oldLst.get(i);
            this.tradeRollbackBalance(change);
            this.tradeProcessTrade(change);
        }

    }

    /**
     * 删除交易
     */
    @Override
    public void deleteTrade(Trade trade) {
        prepareTrade(trade);
        // 删除主交易
        tradeMapper.deleteTrade(trade);
        // 如果不是已经成交的交易，不处理记账
        if (TradeStatus.DEAL.equals(trade.getTradeStatus())) {
            // 查询原来的变动
            List<BalanceChange> oldLst = tradeMapper.queryBalanceChange(trade);
            tradeMapper.deleteBalanceChange(trade);
            for (int i = 0; i < oldLst.size(); i++) {
                BalanceChange change = oldLst.get(i);
                this.tradeRollbackBalance(change);
                this.tradeProcessTrade(change);
            }
        }
        // 删除明细交易
        if (trade.getDetails() != null && trade.getDetails().size() > 0) {
            for (int i = 0; i < trade.getDetails().size(); i++) {
                TradeService service = factory.getTradeService(trade.getDetails().get(i).getTradeType());
                Map map = new HashMap();
                map.put("pTradeId", trade.getTradeId());
                List<Trade> list = tradeMapper.queryTradePByPage(map);
                trade.getDetails().get(i).setTradeId(list.get(0).getTradeId());
                service.deleteTrade(trade.getDetails().get(i));
            }
        }
    }

    /**
     * 交易 风险检查
     */
    @Override
    public CommResponse checkBeforeApproval(Trade trade, Map<String, Map> map) {
        Map<String, Object> ret = new WeakHashMap<>();
        ret.put("warn", ListUtils.EMPTY_LIST);
        ret.put("forbidden", ListUtils.EMPTY_LIST);
        return CommResponse.success(ret);
    }

    /**
     * newCloud
     * 场内对冲交易
     * 导入  新增交易 处理
     */
    @Override
    public Trade tranferTrade(Trade trade) {
        if (SysUtils.equals(trade.getTradeType(), "LongOpen") || SysUtils.equals(trade.getTradeType(), "ShortOpen")) {
            trade.setVolume(trade.getVolume().multiply(new BigDecimal(1)));
            trade.setAmount(trade.getAmount().multiply(new BigDecimal(-1)));
        } else {
            trade.setVolume(trade.getVolume().multiply(new BigDecimal(-1)));
            trade.setAmount(trade.getAmount().multiply(new BigDecimal(1)));
        }
        trade.setFee(trade.getFee().multiply(new BigDecimal(-1)));
        return trade;
    }

    /**
     * newCloud
     * 场内对冲交易
     * 导入  交易
     */
    public CommResponse importTrades(HttpServletRequest request, MultipartFile cmf, String tradeType, Map validMap) {
        // 获得上传文件的文件名
        String fileName = cmf.getOriginalFilename();
        //文件类型
        String extension = FilenameUtils.getExtension(fileName);
        if ("xls,xlsx".toUpperCase().indexOf(extension.toUpperCase()) == -1) {
            return new CommResponse(false, "文件类型不符合要求");
        }
        CommResponse commResponse = new CommResponse(true);
        try {
            Workbook wb = extension.toLowerCase().equals("xls") ? new HSSFWorkbook(cmf.getInputStream()) : new XSSFWorkbook(cmf.getInputStream());
            commResponse = this.getSheetData(wb, wb.getSheetAt(0).getSheetName(), tradeType, validMap);
        } catch (Exception ex) {
            ex.printStackTrace();
            commResponse.setSuccess(false);
            commResponse.setMsg(ex.getMessage());
        }
        return commResponse;
    }

    public CommResponse getSheetData(Workbook wb, String sheetName, String tradeType, Map validMap) {
        if (wb == null) {
            return null;
        }
        Sheet sheet = wb.getSheet(sheetName);
        if (sheet == null) {
            return null;
        }
        CommResponse commRes = new CommResponse(true);
        //数据开始行
        int firstRowNum = 2;
        //列名所在行
        int hraderRowNum = 1;
        FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
        //数据结束行
        int lastRowNum = sheet.getLastRowNum();
        List<Map<String, String>> columnCfglist = new ArrayList<>();

        columnCfglist = (List) validMap.get("columnCfglist");
        Row row = null;
        row = sheet.getRow(hraderRowNum - 1);
        //-------------------------------校验列名----------------------------
        for (int i = 0; i < columnCfglist.size(); i++) {
            Map columnCfgMap = columnCfglist.get(i);
            if (SysUtils.equals(columnCfgMap.get("isImport"), "1")) {
                Cell cell = row.getCell(i);
                if (cell == null) {
                    commRes.setSuccess(false);
                    commRes.setMsg("第" + hraderRowNum + "行" + (i + 1) + "列不能为空");
                    break;
                }
                CellValue cellValue = evaluator.evaluate(cell);
                String colImportName = columnCfgMap.get("headName").toString();
                if (!SysUtils.equals(cellValue.getStringValue(), colImportName)) {
                    commRes.setSuccess(false);
                    commRes.setMsg("第" + hraderRowNum + "行" + (i + 1) + "列值和配置名称不相同，请检查Excel列名！");
                    break;
                }
            }
        }
        if (!commRes.isSuccess()) {
            return commRes;
        }
        //-------------------------------处理数据----------------------------
        List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
        for (int rowIndex = (firstRowNum - 1); rowIndex <= lastRowNum; rowIndex++) {
            row = sheet.getRow(rowIndex);
            if (ExcelImportUtil.isRowEmpty(row)) {
                break;
            }
            Map<String, Object> rd = new LinkedHashMap<String, Object>();
            String str = "{";
            String iCode = null;
            String volume = null;
            String price = null;
            for (int i = 0; i < columnCfglist.size(); i++) {
                JSONObject json = new JSONObject();
                Map<String, String> columnCfgMap = columnCfglist.get(i);
                String colField = String.valueOf(columnCfgMap.get("colField"));
                int colLength = Integer.parseInt(String.valueOf(columnCfgMap.get("colLength")));
                String colType = String.valueOf(columnCfgMap.get("colType"));
                String cellValue = null;
                //判断是否为导入字段
                if (SysUtils.equals(columnCfgMap.get("isImport"), "1")) {
                    Cell cell = row.getCell(i);
                    cellValue = ExcelImportUtil.getValue(cell);
                    //是否需要转换
                    if (SysUtils.equals(columnCfgMap.get("isTransfer"), "1")) {
                        CommResponse commResponse = getTransferValue(columnCfgMap, cellValue, validMap);
                        if (commResponse.isSuccess()) {
                            if (columnCfgMap.get("colField").equals("iCode")) {
                                iCode = String.valueOf(commResponse.getMsg());
                            }
                            cellValue = String.valueOf(commResponse.getMsg());
                        } else {
                            commRes.setSuccess(false);
                            commRes.setMsg("第" + (rowIndex + 1) + "行" + (i + 1) + "列值" + commResponse.getMsg() + "，请检查Excel！");
                            break;
                        }
                    }
                    if (SysUtils.equals(columnCfgMap.get("isInstrument"), "1")) {
                        CommResponse commResponse = getInstrumentValue(columnCfgMap, cellValue, iCode, validMap);
                        if (commResponse.isSuccess()) {
                            Map<String, String> map = (Map<String, String>) commResponse.getMsg();
                            rd.put("aType", map.get("aType"));
                            cellValue = String.valueOf(map.get("mType"));
                        } else {
                            commRes.setSuccess(false);
                            commRes.setMsg("第" + (rowIndex + 1) + "行" + (i + 1) + "列值" + commResponse.getMsg() + "，请检查Excel！");
                            break;
                        }
                    }
                }
                // 负号校验
                if (SysUtils.equals(columnCfgMap.get("allownegative"), "1")) {
                    String substring = cellValue.substring(0, 1);
                    if ("-".equals(substring)) {
                        commRes.setSuccess(false);
                        commRes.setMsg("第" + (rowIndex + 1) + "行" + (i + 1) + "列值不允许负数，请检查Excel！");
                        break;
                    }
                }
                //非空校验
                if (SysUtils.equals(columnCfgMap.get("allowBlank"), "0")) {
                    if (SysUtils.isVoid(cellValue)) {
                        commRes.setSuccess(false);
                        commRes.setMsg("第" + (rowIndex + 1) + "行" + (i + 1) + "列值不能为空，请检查Excel！");
                        break;
                    }
                    if (StrUtil.equals(colType, "NUMBER")) {
                        String reg = "-?[0-9]+(.[0-9]+)?";
                        if (!cellValue.matches(reg)) {
                            commRes.setSuccess(false);
                            commRes.setMsg("第" + (rowIndex + 1) + "行" + (i + 1) + "列值应为数值，请检查Excel！");
                        }
                        double value = Double.parseDouble(cellValue);
                        cellValue = new DecimalFormat("#.00").format(value);
                        if (StrUtil.equals(colField, "volume")) {
                            volume = cellValue;
                        }
                        if (StrUtil.equals(colField, "price")) {
                            price = cellValue;
                        }
                    }
                }
                // 金额校验
                if (SysUtils.equals(columnCfgMap.get("checkamount"), "1")) {
                    double vle = Double.parseDouble(volume);
                    double pie = Double.parseDouble(price);
                    String abs = null;
                    if (cellValue.contains("-")) {
                        abs = cellValue.substring(1);
                    } else {
                        abs = cellValue;
                    }
                    String realAmount = new DecimalFormat("#.00").format(vle * pie);
                    if (!realAmount.equals(abs)) {
                        commRes.setSuccess(false);
                        commRes.setMsg("第" + (rowIndex + 1) + "行" + (i + 1) + "列值错误,金额值应等于数量乘价格，请检查Excel！");
                        break;
                    }
                }
                //长度校验
                if (cellValue.length() > colLength) {
                    commRes.setSuccess(false);
                    commRes.setMsg("第" + (rowIndex + 1) + "行" + (i + 1) + "列值长度超出限制，请检查Excel！");
                    break;
                }

                rd.put(colField, cellValue);
            }
            if (!commRes.isSuccess()) {
                break;
            }
            if (!commRes.isSuccess()) {
                break;
            }
            data.add(rd);
        }
        if (commRes.isSuccess()) {
            //this.validInstruments(data, commRes);
        }

        if (commRes.isSuccess()) {
            commRes.setMsg(data);
        }
//        System.out.println(data);
        return commRes;
    }


    public CommResponse getTransferValue(Map<String, String> columnCfgMap, String cellValue, Map validMap) {
        CommResponse commResponse = CommResponse.success();
        // 校验本方账号是否存在
        if (SysUtils.equals(columnCfgMap.get("colField"), "accId")) {
            Account account = accountMapper.checkAccName(cellValue);
            if (account == null) {
                commResponse.setSuccess(false);
                commResponse.setMsg("本方账户不存在");
            } else {
                commResponse.setMsg(account.getAccId());
            }
            return commResponse;
        }
        // 校验日期是否正确
        if (SysUtils.equals(columnCfgMap.get("colField"), "tradeDate")) {
            try {
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                Date parse = dateFormat.parse(cellValue);
            } catch (Exception e) {
                commResponse.setSuccess(false);
                commResponse.setMsg("日期错误");
                return commResponse;
            }
            commResponse.setMsg(cellValue);
            return commResponse;

        }
        // 检验交易类型并转化
        if (SysUtils.equals(columnCfgMap.get("colField"), "tradeType")) {
            String dictValue = DictUtils.getDictValue("simpleTradeType", cellValue, "");
            if (dictValue.equals(cellValue)) {
                commResponse.setSuccess(false);
                commResponse.setMsg("交易类型不存在");
            } else {
                commResponse.setMsg(dictValue);
            }
            return commResponse;
        }
        // 检验资产代码是否存在
        if (SysUtils.equals(columnCfgMap.get("colField"), "iCode")) {
            HashMap<String, Object> iCode = new HashMap<>();
            iCode.put("iCode", cellValue);
            List<Map<String, Object>> instrument = instrumentMapper.getInstruments(iCode);
            if (instrument == null) {
                commResponse.setSuccess(false);
                commResponse.setMsg("资产代码不存在");
            } else {
                commResponse.setMsg(cellValue);
            }
            return commResponse;
        }
        // 校验币种
        if (SysUtils.equals(columnCfgMap.get("colField"), "currency")) {
            String dictValue = DictUtils.getDictValue("CURRENCY", cellValue, "");
            if (dictValue.equals(cellValue)) {
                commResponse.setSuccess(false);
                commResponse.setMsg("币种不存在");
            } else {
                commResponse.setMsg(dictValue);
            }
            return commResponse;
        }
        return commResponse;
    }

    public CommResponse getInstrumentValue(Map<String, String> columnCfgMap, String cellValue, String iCode, Map validMap) {
        CommResponse commResponse = CommResponse.success();
        // 检验市场类型并转化
        if (SysUtils.equals(columnCfgMap.get("colField"), "mType")) {
            String dictValue = DictUtils.getDictValue("M_TYPE", cellValue, "");
            if (dictValue.equals(cellValue)) {
                commResponse.setSuccess(false);
                commResponse.setMsg("市场类型不存在");
            } else {
                HashMap<String, Object> mType = new HashMap<>();
                mType.put("iCode", iCode);
                mType.put("mType", dictValue);
                List<Map<String, Object>> instrument = instrumentMapper.getInstruments(mType);
                if (instrument.size() != 1) {
                    commResponse.setSuccess(false);
                    commResponse.setMsg("资产类型与市场类型不匹配");
                    return commResponse;
                }
                HashMap<String, String> aMmap = new HashMap<>();
                Map<String, Object> instrumentMap = instrument.get(0);
                aMmap.put("aType", (String) instrumentMap.get("a_type"));
                aMmap.put("mType", (String) instrumentMap.get("m_type"));
                commResponse.setMsg(aMmap);
            }
        }
        return commResponse;
    }

    /**
     * newCloud
     * 场内对冲交易
     * 导入  交易字段列表
     */
    @Override
    public List getTradeColumnCfglist() {
        List<Map<String, String>> columnCfglist = new ArrayList<>();
        Map<String, String> headMap = new HashMap();
        headMap.put("headName", "本方账户");
        headMap.put("colField", "accId");
        headMap.put("colType", "VARCHAR2");
        headMap.put("colLength", "200");
        headMap.put("allowBlank", "0");
        headMap.put("isImport", "1");
        headMap.put("isTransfer", "1");
        columnCfglist.add(headMap);
        headMap = new HashMap();
        headMap.put("headName", "交易日期");
        headMap.put("colField", "tradeDate");
        headMap.put("colType", "VARCHAR2");
        headMap.put("colLength", "100");
        headMap.put("allowBlank", "0");
        headMap.put("isImport", "1");
        headMap.put("isTransfer", "0");
        columnCfglist.add(headMap);
        headMap = new HashMap();
        headMap.put("headName", "交易类型");
        headMap.put("colField", "tradeType");
        headMap.put("colType", "VARCHAR2");
        headMap.put("colLength", "100");
        headMap.put("allowBlank", "0");
        headMap.put("isImport", "1");
        headMap.put("isTransfer", "1");
        columnCfglist.add(headMap);
        headMap = new HashMap();
        headMap.put("headName", "资产代码");
        headMap.put("colField", "iCode");
        headMap.put("colType", "VARCHAR2");
        headMap.put("colLength", "100");
        headMap.put("allowBlank", "0");
        headMap.put("isImport", "1");
        headMap.put("isTransfer", "0");
        columnCfglist.add(headMap);
        headMap = new HashMap();
        headMap.put("headName", "市场类型");
        headMap.put("colField", "mType");
        headMap.put("colType", "VARCHAR2");
        headMap.put("colLength", "100");
        headMap.put("allowBlank", "0");
        headMap.put("isImport", "1");
        headMap.put("isTransfer", "1");
        columnCfglist.add(headMap);
        headMap = new HashMap();
        headMap.put("headName", "数量");
        headMap.put("colField", "volume");
        headMap.put("colType", "NUMBER");
        headMap.put("colLength", "50");
        headMap.put("allowBlank", "0");
        headMap.put("isImport", "1");
        headMap.put("isTransfer", "0");
        columnCfglist.add(headMap);
        headMap = new HashMap();
        headMap.put("headName", "价格");
        headMap.put("colField", "price");
        headMap.put("colType", "NUMBER");
        headMap.put("colLength", "10");
        headMap.put("allowBlank", "0");
        headMap.put("isImport", "1");
        headMap.put("isTransfer", "0");
        columnCfglist.add(headMap);
        headMap = new HashMap();
        headMap.put("headName", "金额");
        headMap.put("colField", "amount");
        headMap.put("colType", "NUMBER");
        headMap.put("colLength", "30");
        headMap.put("allowBlank", "0");
        headMap.put("isImport", "1");
        headMap.put("isTransfer", "0");
        columnCfglist.add(headMap);
        headMap = new HashMap();
        headMap.put("headName", "费用");
        headMap.put("colField", "fee");
        headMap.put("colType", "NUMBER");
        headMap.put("colLength", "30");
        headMap.put("allowBlank", "0");
        headMap.put("isImport", "1");
        headMap.put("isTransfer", "0");
        columnCfglist.add(headMap);
        return columnCfglist;
    }


}
